{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第一个作业"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### reduce"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import re\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    handler = sys.stdin\n",
    "    word_dict = {}\n",
    "    for line in handler:\n",
    "        if not line:\n",
    "            continue\n",
    "        terms = line.strip().split(\" \")\n",
    "        for i in terms:\n",
    "            if i in word_dict:\n",
    "                word_dict[i] += 1\n",
    "            else:\n",
    "                word_dict[i] = 1\n",
    "\n",
    "    for j in word_dict:\n",
    "        print(j, word_dict[j])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import re\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    handler = sys.stdin\n",
    "    for line in handler:\n",
    "        if not line:\n",
    "            continue\n",
    "        terms = line.strip().split(\" \")\n",
    "        for i in terms:\n",
    "            print(i)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二个作业"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "   * 每行第一字母表示本人，其他字母他的朋友，找出有共同朋友的人，和共同朋友是谁，如何使用MapReduce来实现 20分 \n",
    "   * ABCDEF \n",
    "   * BACDE \n",
    "   * CABE \n",
    "   * DABE \n",
    "   * EABCD \n",
    "   * FA \n",
    "\n",
    "\n",
    "   * 结果：\n",
    "   * ####################################\n",
    "   * AB      E:C:D\n",
    "   * AC      E:B\n",
    "   * AD      B:E\n",
    "   * AE      C:B:D\n",
    "   * BC      A:E\n",
    "   * BD      A:E\n",
    "   * BE      C:D:A\n",
    "   * BF      A\n",
    "   * CD      E:A:B\n",
    "   * CE      A:B\n",
    "   * CF      A\n",
    "   * DE      B:A\n",
    "   * DF      A\n",
    "   * EF      A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
